package com.panshi.controller;

import com.panshi.service.IReplyService;
import com.panshi.vo.qa.DataResultQA;
import com.panshi.vo.qa.Pages;
import com.panshi.vo.qa.Reply;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Api(tags = "回答业务接口")
@Slf4j
@Controller
@RequestMapping(value = "/reply", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class ReplyController {

    @Autowired
    IReplyService replyService;

   /* //添加回答
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    @ApiOperation("回答添加")
    @ApiImplicitParam(name = "reply",value = "回答信息",required = true)
    boolean addReply(@RequestBody Reply reply){
        log.info("请求路径：{},参数：{}","/reply/add",reply);
        boolean boo = replyService.addReply(reply);
        return boo;
    }*/

    //分页查询
    @PostMapping(value = "/inquirePages")
    @ResponseBody
    @ApiOperation("分页查询")
    @ApiImplicitParam(name = "pages",value = "分页查询条件",required = true)
    public DataResultQA<Pages<Reply>> inquirePagesReply(@RequestBody Pages pages){
        log.info("请求路径：{},参数：{}","/reply/inquirePages",pages);
        DataResultQA<Pages<Reply>> dataResultQA = new DataResultQA();
        if(pages.getStartPage() < 0 || pages.getPageSize() <= 0){
            dataResultQA.setCode(110);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("参数不正确！");
            return dataResultQA;
        }
        Pages<Reply> p = replyService.inquirePagesReply(pages);
        dataResultQA.setCode(200);
        dataResultQA.setBoo(true);
        dataResultQA.setDescribe("分页查询完成！");
        dataResultQA.setData(p);
        return dataResultQA;
    }

    //查询总记录数
    @PostMapping(value = "/inquireSum")
    @ResponseBody
    @ApiOperation("查询总记录数")
    @ApiImplicitParam(name = "pages",value = "查询条件",required = true)
    public DataResultQA<Integer> inquireReplySum(@RequestBody Pages pages){
        log.info("请求路径：{},参数：{}","/reply/inquireSum",pages);
        DataResultQA<Integer> dataResultQA = new DataResultQA();
        if(pages.getStartPage() < 0 || pages.getPageSize() <= 0){
            dataResultQA.setCode(110);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("参数不正确！");
            return dataResultQA;
        }
        Integer sum = replyService.inquireReplySum(pages);
        dataResultQA.setCode(200);
        dataResultQA.setBoo(true);
        dataResultQA.setDescribe("查询数据条数！");
        dataResultQA.setData(sum);
        return dataResultQA;
    }

    //通过id查询回答
    @PostMapping(value = "/inquireById/{id}")
    @ResponseBody
    @ApiOperation("通过id查询回答")
    @ApiImplicitParam(name = "id",value = "回答id",required = true)
    public DataResultQA<Reply> inquireById(@PathVariable int id){
        log.info("请求路径：{},参数：{}","/reply/inquireById/{id}",id);
        DataResultQA<Reply> dataResultQA = new DataResultQA<>();
        if(id <= 0){
            dataResultQA.setCode(110);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("参数不正确！");
            return dataResultQA;
        }
        Reply reply = replyService.inquireById(id);
        dataResultQA.setCode(200);
        dataResultQA.setBoo(true);
        dataResultQA.setDescribe("根据id查询！");
        dataResultQA.setData(reply);
        return dataResultQA;
    }

    //点赞总数加一
    @GetMapping(value = "/praiseSumAnd1/{id}")
    @ResponseBody
    @ApiOperation("点赞加一")
    @ApiImplicitParam(name = "id",value = "回答id",required = true)
    public  DataResultQA praiseSumAnd1(@PathVariable int id){
        log.info("请求路径：{},参数：{}","/reply/praiseSumAnd1/{id}",id);
        DataResultQA dataResultQA = new DataResultQA();
        if(id <= 0){
            dataResultQA.setCode(110);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("参数不正确！");
            return dataResultQA;
        }
        boolean boo = replyService.praiseSumAnd1(id);
        if(boo){
            dataResultQA.setCode(200);
            dataResultQA.setBoo(true);
            dataResultQA.setDescribe("点赞完成！");
        }else{
            dataResultQA.setCode(120);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("点赞失败！");
        }
        return dataResultQA;
    }

    //点赞总数减一
    @GetMapping(value = "/praiseSumSubtract1/{id}")
    @ResponseBody
    @ApiOperation("点赞减一")
    @ApiImplicitParam(name = "id",value = "回答id",required = true)
    public DataResultQA praiseSumSubtract1(@PathVariable int id){
        log.info("请求路径：{},参数：{}","/reply/praiseSumSubtract1/{id}",id);
        DataResultQA dataResultQA = new DataResultQA();
        if(id <= 0){
            dataResultQA.setCode(110);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("参数不正确！");
            return dataResultQA;
        }
        boolean boo = replyService.praiseSumSubtract1(id);
        if(boo){
            dataResultQA.setCode(200);
            dataResultQA.setBoo(true);
            dataResultQA.setDescribe("取消点赞完成！");
        }else{
            dataResultQA.setCode(120);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("取消点赞失败！");
        }
        return dataResultQA;
    }

    //点踩总数加一
    @GetMapping(value = "/trampleSumAnd1/{id}")
    @ResponseBody
    @ApiOperation("点踩加一")
    @ApiImplicitParam(name = "id",value = "回答id",required = true)
    public DataResultQA trampleSumAnd1(@PathVariable int id){
        log.info("请求路径：{},参数：{}","/reply/trampleSumAnd1/{id}",id);
        DataResultQA dataResultQA = new DataResultQA();
        if(id <= 0){
            dataResultQA.setCode(110);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("参数不正确！");
            return dataResultQA;
        }
        boolean boo = replyService.trampleSumAnd1(id);
        if(boo){
            dataResultQA.setCode(200);
            dataResultQA.setBoo(true);
            dataResultQA.setDescribe("点踩完成！");
        }else{
            dataResultQA.setCode(120);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("点踩失败！");
        }
        return dataResultQA;
    }

    //点踩总数减一
    @GetMapping(value = "/trampleSumSubtract1/{id}")
    @ResponseBody
    @ApiOperation("点踩减一")
    @ApiImplicitParam(name = "id",value = "回答id",required = true)
    public DataResultQA trampleSumSubtract1(@PathVariable int id){
        log.info("请求路径：{},参数：{}","/reply/trampleSumSubtract1/{id}",id);
        DataResultQA dataResultQA = new DataResultQA();
        if(id <= 0){
            dataResultQA.setCode(110);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("参数不正确！");
            return dataResultQA;
        }
        boolean boo = replyService.trampleSumSubtract1(id);
        if(boo){
            dataResultQA.setCode(200);
            dataResultQA.setBoo(true);
            dataResultQA.setDescribe("取消点踩完成！");
        }else{
            dataResultQA.setCode(120);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("取消点踩失败！");
        }
        return dataResultQA;
    }

    //删除(标记删除)
    @GetMapping(value = "/delete/{id}")
    @ResponseBody
    @ApiOperation("删除(标记删除)")
    @ApiImplicitParam(name = "id",value = "回答id",required = true)
    public DataResultQA deleteReply(@PathVariable int id){
        log.info("请求路径：{},参数：{}","/reply/delete/{id}",id);
        DataResultQA dataResultQA = new DataResultQA();
        if(id <= 0){
            dataResultQA.setCode(110);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("参数不正确！");
            return dataResultQA;
        }
        boolean boo = replyService.deleteReply(id);
        if(boo){
            dataResultQA.setCode(200);
            dataResultQA.setBoo(true);
            dataResultQA.setDescribe("标记删除完成！");
        }else{
            dataResultQA.setCode(120);
            dataResultQA.setBoo(false);
            dataResultQA.setDescribe("标记删除失败！");
        }
        return dataResultQA;
    }

}
